' ======================================================================
' 执行所有 case
' ======================================================================
Public Sub test_all_case()
    test_writeUtf8NobomFile
    test_writeUtf8NobomEmptyFile
    test_writeTxtFile
    test_writeTxtEmptyFile
    test_writeUtf8NobomFileAuto
    test_writeUtf8NobomEmptyFileAuto
    test_writeTxtFileAuto
    test_writeTxtEmptyFileAuto
    ' readTxtFile 在之前的测试中已经存在，不需要在做测试
    ' readTxtFile
    test_readFileToHexArray
    test_readFileWithEncoding
    test_readFileWithUtf8
    test_readFileByteArray
    test_splitFileBySize
    test_mergeFiles
    test_copyFile
    ' 该方法需要手动测试
    ' test_copyStr2Clipboard
    test_copyFileToHexStrFile
    test_copyHexStrToRealFile
    ' tryDeleteFile 在之前的测试中已经存在，不需要在做测试
    ' tryDeleteFile
    test_getFileByteCount
    test_extension
    test_cutExt
    test_getNoExtFileName
    test_getFileNthLevelExtension
    test_getFile1stLevelExtension
    test_getFile2ndLevelExtension
    test_getFile3rdLevelExtension
    test_dirExist
    ' rmdir 在之前的测试中已经存在，不需要在做测试
    ' rmdir
    test_filenameListFromFolder
    test_filenameListFromFolderByPattern
    test_getFirstMatchedFilenameFromFolder
    test_getFirstMatchedFilenameFromFolderByPattern
    test_walkFolderAndGetFilePathList
    test_walkFolderAndGetFilePathListByPattern
    test_filepathListFromFolder
    test_filepathListFromFolderByPattern
    test_getFirstMatchedFilepathFromFolder
    test_getFirstMatchedFilepathFromFolderByPattern
    test_pathExist
    test_isFile
    test_isDir
    test_joinPath
    test_dirname
    test_getBasename
    ' 该方法无法测试
    ' getShortPath
    test_getThisWorkbookDir
    ' 该方法无法测试
    ' getThisWorkbookShortDir
    test_isWinAbsolutePath
End Sub

' ======================================================================
' 测试 case
' ======================================================================
Private Sub test_writeUtf8NobomFile()
    Dim str As String
    str = "aaaaa" & vbLf _
        & "bbbbbb" & vbLf _
        & "cccccc" & vbLf _
        & "dddddd" & vbLf

    Dim path As String
    path = ThisWorkbook.path & "\text.txt"

    ' 1. 输出字符串到文件
    UtilsIO.writeUtf8NobomFile path, str

    ' 2. 检查结果
    Debug.Assert UtilsIO.readTxtFile(path) = str

    ' 3. 收尾: 删除测试文件
    UtilsIO.tryDeleteFile path
End Sub

Private Sub test_writeUtf8NobomEmptyFile()
    Dim path As String
    path = ThisWorkbook.path & "\text.txt"

    ' 1. 执行方法
    UtilsIO.writeUtf8NobomEmptyFile path

    ' 2. 测试结果
    Debug.Assert UtilsIO.readTxtFile(path) = ""

    ' 3. 收尾: 删除测试文件
    UtilsIO.tryDeleteFile path
End Sub

Private Sub test_writeTxtFile()
    Dim str As String
    str = "aaaaa" & vbLf _
        & "bbbbbb" & vbLf _
        & "cccccc" & vbLf _
        & "dddddd" & vbLf _
        & "eeeeee"

    Dim path As String
    path = ThisWorkbook.path & "\text.txt"

    ' 1. 输出字符串到文件
    UtilsIO.writeTxtFile path, str

    ' 2. 检查结果
    Debug.Assert UtilsIO.readTxtFile(path) = str

    ' 3. 收尾: 删除测试文件
    UtilsIO.tryDeleteFile path
End Sub

Private Sub test_writeTxtEmptyFile()
    Dim path As String
    path = ThisWorkbook.path & "\text.txt"

    ' 1. 执行方法
    UtilsIO.writeTxtEmptyFile path

    ' 2. 检查结果
    Debug.Assert UtilsIO.readTxtFile(path) = ""

    ' 3. 收尾: 删除测试文件
    UtilsIO.tryDeleteFile path
End Sub

Private Sub test_writeUtf8NobomFileAuto()
    Dim str As String
    str = "aaaaa" & vbLf _
        & "bbbbbb" & vbLf _
        & "cccccc" & vbLf _
        & "dddddd" & vbLf

    Dim path As String
    path = ThisWorkbook.path & "\testDir\text.txt"

    ' 1. 执行方法
    UtilsIO.writeUtf8NobomFileAuto path, str

    ' 2. 检查结果
    Debug.Assert UtilsIO.readTxtFile(path) = str

    ' 3. 收尾: 删除目录
    UtilsIO.rmdir ThisWorkbook.path & "\testDir"
End Sub

Private Sub test_writeUtf8NobomEmptyFileAuto()
    Dim path As String
    path = ThisWorkbook.path & "\testDir\text.txt"

    ' 1. 执行方法
    UtilsIO.writeUtf8NobomEmptyFileAuto path

    ' 2. 检查结果
    Debug.Assert UtilsIO.readTxtFile(path) = ""

    ' 3. 收尾: 删除目录
    UtilsIO.rmdir ThisWorkbook.path & "\testDir"
End Sub

Private Sub test_writeTxtFileAuto()
    Dim str As String
    str = "aaaaa" & vbLf _
        & "bbbbbb" & vbLf _
        & "cccccc" & vbLf _
        & "dddddd" & vbLf

    Dim path As String
    path = ThisWorkbook.path & "\testDir\text.txt"

    ' 1. 执行方法
    UtilsIO.writeTxtFileAuto path, str

    ' 2. 检查结果
    Debug.Assert UtilsIO.readTxtFile(path) = str

    ' 3. 收尾: 删除目录
    UtilsIO.rmdir ThisWorkbook.path & "\testDir"
End Sub

Private Sub test_writeTxtEmptyFileAuto()
    Dim path As String
    path = ThisWorkbook.path & "\testDir\text.txt"

    ' 1. 执行方法
    UtilsIO.writeTxtEmptyFileAuto path

    ' 2. 检查结果
    Debug.Assert UtilsIO.readTxtFile(path) = ""

    ' 3. 收尾: 删除目录
    UtilsIO.rmdir ThisWorkbook.path & "\testDir"
End Sub

Private Sub test_readFileToHexArray()
    Dim str As String
    str = "ABC"

    Dim path As String
    path = ThisWorkbook.path & "\text.txt"

    ' 1. 写出文件方法
    UtilsIO.writeTxtFile path, str

    ' 2. 读取文件
    Dim arr As IPrimitiveArrayRef
    Set arr = UtilsIO.readFileToHexArray(path)
    ' 3.检查结果
    Debug.Assert arr.Count = 3
    Debug.Assert arr.Item(0) = 41' 65
    Debug.Assert arr.Item(1) = 42' 66
    Debug.Assert arr.Item(2) = 43' 67

    ' 4. 收尾: 删除文件
    UtilsIO.tryDeleteFile path
End Sub

Private Sub test_readFileWithEncoding()
    Dim str As String
    str = "aaaaa" & vbLf _
        & "bbbbbb" & vbLf _
        & "cccccc" & vbLf _
        & "dddddd" & vbLf

    Dim path As String
    path = ThisWorkbook.path & "\text.txt"

    ' 1. 输出字符串到文件
    UtilsIO.writeUtf8NobomFile path, str

    ' 2. 检查结果
    Debug.Assert UtilsIO.readFileWithEncoding(path, "utf-8") = str

    ' 3. 收尾: 删除测试文件
    UtilsIO.tryDeleteFile path
End Sub

Private Sub test_readFileWithUtf8()
    Dim str As String
    str = "aaaaa" & vbLf _
        & "bbbbbb" & vbLf _
        & "cccccc" & vbLf _
        & "dddddd" & vbLf

    Dim path As String
    path = ThisWorkbook.path & "\text.txt"

    ' 1. 输出字符串到文件
    UtilsIO.writeUtf8NobomFile path, str

    ' 2. 检查结果
    Debug.Assert UtilsIO.readFileWithUtf8(path) = str

    ' 3. 收尾: 删除测试文件
    UtilsIO.tryDeleteFile path
End Sub

Private Sub test_readFileByteArray()
    Dim str As String
    Dim path As String
    path = ThisWorkbook.path & "\text.txt"
    Dim arr As IPrimitiveArrayRef

    ' ==============================
    ' 1. 测试有数据的文件
    ' ==============================
    ' 1. 输出字符串到文件
    str = "ABC"
    UtilsIO.writeUtf8NobomFile path, str

    ' 2. 执行方法
    Set arr = UtilsIO.readFileByteArray(path)

    ' 3. 检查结果
    Debug.Assert arr.Count = 3
    Debug.Assert arr.Item(0) = 65
    Debug.Assert arr.Item(1) = 66
    Debug.Assert arr.Item(2) = 67

    ' 4. 收尾: 删除测试文件
    UtilsIO.tryDeleteFile path

    ' ==============================
    ' 2. 测试空文件
    ' ==============================
    ' 1. 输出一个空文件
    UtilsIO.writeTxtEmptyFile path

    ' 2. 执行方法
    Set arr = UtilsIO.readFileByteArray(path)

    ' 3. 检查结果
    Debug.Assert arr.Count = 0

    ' 4. 收尾: 删除测试文件
    UtilsIO.tryDeleteFile path
End Sub

Private Sub test_splitFileBySize()
    Dim str As String
    str = "aaaaaa" & vbLf _
        & "bbbbbb" & vbLf _
        & "cccccc" & vbLf _
        & "dddddd" & vbLf

    Dim path As String
    path = ThisWorkbook.path & "\text.txt"

    ' 1. 输出字符串到文件
    UtilsIO.writeUtf8NobomFile path, str

    ' 2. 执行方法
    Dim fileCount As Long
    fileCount = UtilsIO.splitFileBySize(path, ThisWorkbook.path, "ntx", 7)

    ' 3. 检查结果
    Debug.Assert fileCount = 4
    Debug.Assert UtilsIO.readTxtFile(ThisWorkbook.path & "\ntx_1") = "aaaaaa" & vbLf
    Debug.Assert UtilsIO.readTxtFile(ThisWorkbook.path & "\ntx_2") = "bbbbbb" & vbLf
    Debug.Assert UtilsIO.readTxtFile(ThisWorkbook.path & "\ntx_3") = "cccccc" & vbLf
    Debug.Assert UtilsIO.readTxtFile(ThisWorkbook.path & "\ntx_4") = "dddddd" & vbLf

    ' 4. 收尾: 删除测试文件
    UtilsIO.tryDeleteFile path
    UtilsIO.tryDeleteFile ThisWorkbook.path & "\ntx_1"
    UtilsIO.tryDeleteFile ThisWorkbook.path & "\ntx_2"
    UtilsIO.tryDeleteFile ThisWorkbook.path & "\ntx_3"
    UtilsIO.tryDeleteFile ThisWorkbook.path & "\ntx_4"
End Sub

Private Sub test_mergeFiles()
    Dim str1 As String
    Dim str2 As String
    Dim str3 As String
    Dim str4 As String
    str1 = "aaaaaa" & vbLf
    str2 = "bbbbbb" & vbLf
    str3 = "cccccc" & vbLf
    str4 = "dddddd" & vbLf

    Dim path1 As String
    Dim path2 As String
    Dim path3 As String
    Dim path4 As String
    path1 = ThisWorkbook.path & "\text1.txt"
    path2 = ThisWorkbook.path & "\text2.txt"
    path3 = ThisWorkbook.path & "\text3.txt"
    path4 = ThisWorkbook.path & "\text4.txt"

    ' 1. 输出字符串到文件
    UtilsIO.writeUtf8NobomFile path1, str1
    UtilsIO.writeUtf8NobomFile path2, str2
    UtilsIO.writeUtf8NobomFile path3, str3
    UtilsIO.writeUtf8NobomFile path4, str4

    ' 2. 执行方法
    UtilsIO.mergeFiles ThisWorkbook.path, "text.txt", path1, path2, path3, path4

    ' 3. 检查结果
    Debug.Assert UtilsIO.readTxtFile(ThisWorkbook.path & "\text.txt") = str1 & str2 & str3 & str4

    ' 4. 收尾: 删除测试文件
    UtilsIO.tryDeleteFile path1
    UtilsIO.tryDeleteFile path2
    UtilsIO.tryDeleteFile path3
    UtilsIO.tryDeleteFile path4
    UtilsIO.tryDeleteFile ThisWorkbook.path & "\text.txt"
End Sub

Private Sub test_copyFile()
    Dim str As String
    str = "aaaaaa" & vbLf _
        & "bbbbbb" & vbLf _
        & "cccccc" & vbLf _
        & "dddddd" & vbLf

    Dim path As String
    Dim copyPath As String
    path = ThisWorkbook.path & "\text.txt"
    copyPath = ThisWorkbook.path & "\text2.txt"

    ' 1. 输出字符串到文件
    UtilsIO.writeUtf8NobomFile path, str

    ' 2. 执行方法
    UtilsIO.copyFile path, copyPath

    ' 3. 检查结果
    Debug.Assert UtilsIO.readTxtFile(copyPath) = str

    ' 4. 收尾: 删除测试文件
    UtilsIO.tryDeleteFile path
    UtilsIO.tryDeleteFile copyPath
End Sub

' 以下方法需要手动测试
Private Sub test_copyStr2Clipboard()
    UtilsIO.copyStr2Clipboard "copyStr2ClipboardTest"

    With ThisWorkbook.ActiveSheet
        .Range("A1").Select
        .Paste
    End With

End Sub

Private Sub test_copyFileToHexStrFile()
    Dim str As String
    str = "ABC"

    Dim path1 As String
    Dim path2 As String
    path1 = ThisWorkbook.path & "\text.txt"
    path2 = ThisWorkbook.path & "\text2.txt"

    ' 1. 写出文件方法
    UtilsIO.writeTxtFile path1, str

    ' 2. 执行方法
    UtilsIO.copyFileToHexStrFile path1, path2

    ' 3. 检查结果
    Debug.Assert UtilsIO.readTxtFile(path2) = "41 42 43"

    ' 4. 收尾: 删除文件
    UtilsIO.tryDeleteFile path1
    UtilsIO.tryDeleteFile path2
End Sub

Private Sub test_copyHexStrToRealFile()
    Dim str As String
    str = "41 42 43"

    Dim path1 As String
    Dim path2 As String
    path1 = ThisWorkbook.path & "\text.txt"
    path2 = ThisWorkbook.path & "\text2.txt"

    ' 1. 写出文件方法
    UtilsIO.writeTxtFile path1, str

    ' 2. 执行方法
    UtilsIO.copyHexStrToRealFile path1, path2

    ' 3. 检查结果
    Debug.Assert UtilsIO.readTxtFile(path2) = "ABC"

    ' 4. 收尾: 删除文件
    UtilsIO.tryDeleteFile path1
    UtilsIO.tryDeleteFile path2
End Sub

Private Sub test_getFileByteCount()
    Dim str As String
    str = "abc"

    Dim path As String
    path = ThisWorkbook.path & "\text.txt"

    ' 1. 创建文件
    UtilsIO.writeTxtFile path, str

    ' 2. 执行方法
    Dim result As Double
    result = UtilsIO.getFileByteCount(path)

    ' 3. 检查结果
    Debug.Assert result = 3

    ' 4. 收尾: 删除文件
    UtilsIO.tryDeleteFile path
End Sub

Private Sub test_extension()
    Dim a As String
    Dim result As String

    ' ---------case1---------
    a = "a\b.c\d\aaaa.bbb"
    result = UtilsIO.extension(a)
    Debug.Assert result = "bbb"

    ' ---------case2---------
    a = "aaaa.bbb"
    result = UtilsIO.extension(a)
    Debug.Assert result = "bbb"

    ' ---------case3---------
    a = "C:\test\1.xlsx"
    result = UtilsIO.extension(a)
    Debug.Assert result = "xlsx"

    ' ---------case4---------
    a = "aaa."
    result = UtilsIO.extension(a)
    Debug.Assert result = ""
End Sub

Private Sub test_cutExt()
    Dim a As String
    Dim result As String

    a = "aaaa1.bbb"
    result = UtilsIO.cutExt(a)
    Debug.Assert result = "aaaa1"

    a = "aaaa."
    result = UtilsIO.cutExt(a)
    Debug.Assert result = "aaaa."

    a = "aaaa"
    result = UtilsIO.cutExt(a)
    Debug.Assert result = "aaaa"
End Sub

Private Sub test_getNoExtFileName()
    Dim result As String

    result = UtilsIO.getNoExtFileName("x1/x2/x3/myFile.aaa.bbb.ccc.ddd")
    Debug.Assert result = "myFile"

    result = UtilsIO.getNoExtFileName("x1/x2/x3/myFile")
    Debug.Assert result = "myFile"

    result = UtilsIO.getNoExtFileName("x1/x2/x3/myFile.aaa")
    Debug.Assert result = "myFile"

    result = UtilsIO.getNoExtFileName("myFile.aaa.bbb.ccc.ddd")
    Debug.Assert result = "myFile"

    result = UtilsIO.getNoExtFileName("myFile")
    Debug.Assert result = "myFile"

    result = UtilsIO.getNoExtFileName("myFile.aaa")
    Debug.Assert result = "myFile"

    result = UtilsIO.getNoExtFileName("")
    Debug.Assert result = ""

    result = UtilsIO.getNoExtFileName(".aaa")
    Debug.Assert result = ""

    result = UtilsIO.getNoExtFileName(".aaa.bbb")
    Debug.Assert result = ""

    result = UtilsIO.getNoExtFileName("x1/x2/x3/.aaa.bbb")
    Debug.Assert result = ""

    result = UtilsIO.getNoExtFileName("x1/x2/x3/.aaa")
    Debug.Assert result = ""

    result = UtilsIO.getNoExtFileName("x1/x2/x3/.")
    Debug.Assert result = ""

    result = UtilsIO.getNoExtFileName("x1/x2/x3/")
    Debug.Assert result = ""
End Sub

Public Sub test_getFileNthLevelExtension()
    Dim result As String

    ' ==================================================
    ' 有文件名
    ' ==================================================
    result = UtilsIO.getFileNthLevelExtension("x1/x2/x3/myFile.aaa.bbb.ccc.ddd", 2)
    Debug.Assert result = "ccc"

    result = UtilsIO.getFileNthLevelExtension("x1/x2/x3/myFile.bbb.ccc.ddd", 2)
    Debug.Assert result = "ccc"

    result = UtilsIO.getFileNthLevelExtension("x1/x2/x3/myFile.ccc.ddd", 2)
    Debug.Assert result = "ccc"

    result = UtilsIO.getFileNthLevelExtension("x1/x2/x3/myFile.ddd", 2)
    Debug.Assert result = ""

    result = UtilsIO.getFileNthLevelExtension("x1/x2/x3/myFile", 2)
    Debug.Assert result = ""

    result = UtilsIO.getFileNthLevelExtension("x1/x2/x3/myFile.", 2)
    Debug.Assert result = ""

    result = UtilsIO.getFileNthLevelExtension("x1/x2/x3/myFile..", 2)
    Debug.Assert result = ""

    result = UtilsIO.getFileNthLevelExtension("x1/x2/x3/myFile.ccc.", 2)
    Debug.Assert result = "ccc"

    result = UtilsIO.getFileNthLevelExtension("x1/x2/x3/myFile..ddd", 2)
    Debug.Assert result = ""

    ' ==================================================
    ' 文件名为空字符串
    ' ==================================================
    result = UtilsIO.getFileNthLevelExtension("x1/x2/x3/.aaa.bbb.ccc.ddd", 2)
    Debug.Assert result = "ccc"

    result = UtilsIO.getFileNthLevelExtension("x1/x2/x3/.bbb.ccc.ddd", 2)
    Debug.Assert result = "ccc"

    result = UtilsIO.getFileNthLevelExtension("x1/x2/x3/.ccc.ddd", 2)
    Debug.Assert result = "ccc"

    result = UtilsIO.getFileNthLevelExtension("x1/x2/x3/.ddd", 2)
    Debug.Assert result = ""

    result = UtilsIO.getFileNthLevelExtension("x1/x2/x3/", 2)
    Debug.Assert result = ""

    result = UtilsIO.getFileNthLevelExtension("x1/x2/x3/.", 2)
    Debug.Assert result = ""

    result = UtilsIO.getFileNthLevelExtension("x1/x2/x3/..", 2)
    Debug.Assert result = ""

    result = UtilsIO.getFileNthLevelExtension("x1/x2/x3/.ccc.", 2)
    Debug.Assert result = "ccc"

    result = UtilsIO.getFileNthLevelExtension("x1/x2/x3/..ddd", 2)
    Debug.Assert result = ""

    ' ==================================================
    ' 不存在前缀路径 + 有文件名
    ' ==================================================
    result = UtilsIO.getFileNthLevelExtension("myFile.aaa.bbb.ccc.ddd", 2)
    Debug.Assert result = "ccc"

    result = UtilsIO.getFileNthLevelExtension("myFile.bbb.ccc.ddd", 2)
    Debug.Assert result = "ccc"

    result = UtilsIO.getFileNthLevelExtension("myFile.ccc.ddd", 2)
    Debug.Assert result = "ccc"

    result = UtilsIO.getFileNthLevelExtension("myFile.ddd", 2)
    Debug.Assert result = ""

    result = UtilsIO.getFileNthLevelExtension("myFile", 2)
    Debug.Assert result = ""

    result = UtilsIO.getFileNthLevelExtension("myFile.", 2)
    Debug.Assert result = ""

    result = UtilsIO.getFileNthLevelExtension("myFile..", 2)
    Debug.Assert result = ""

    result = UtilsIO.getFileNthLevelExtension("myFile.ccc.", 2)
    Debug.Assert result = "ccc"

    result = UtilsIO.getFileNthLevelExtension("myFile..ddd", 2)
    Debug.Assert result = ""

    ' ==================================================
    ' 不存在前缀路径 + 文件名为空字符串
    ' ==================================================
    result = UtilsIO.getFileNthLevelExtension(".aaa.bbb.ccc.ddd", 2)
    Debug.Assert result = "ccc"

    result = UtilsIO.getFileNthLevelExtension(".bbb.ccc.ddd", 2)
    Debug.Assert result = "ccc"

    result = UtilsIO.getFileNthLevelExtension(".ccc.ddd", 2)
    Debug.Assert result = "ccc"

    result = UtilsIO.getFileNthLevelExtension(".ddd", 2)
    Debug.Assert result = ""

    result = UtilsIO.getFileNthLevelExtension("", 2)
    Debug.Assert result = ""

    result = UtilsIO.getFileNthLevelExtension(".", 2)
    Debug.Assert result = ""

    result = UtilsIO.getFileNthLevelExtension("..", 2)
    Debug.Assert result = ""

    result = UtilsIO.getFileNthLevelExtension(".ccc.", 2)
    Debug.Assert result = "ccc"

    result = UtilsIO.getFileNthLevelExtension("..ddd", 2)
    Debug.Assert result = ""

    ' ==================================================
    ' 前缀路径中存在 .
    ' ==================================================
    result = UtilsIO.getFileNthLevelExtension("x1/x2/x.3/myFile.aaa", 2)
    Debug.Assert result = ""

    result = UtilsIO.getFileNthLevelExtension("x1/x.2/x.3/myFile", 2)
    Debug.Assert result = ""

    result = UtilsIO.getFileNthLevelExtension("x1/x.2/x.3/myFile.aaa.bbb", 2)
    Debug.Assert result = "aaa"

    ' ==================================================
    ' 级别边界测试 .
    ' ==================================================
    result = UtilsIO.getFileNthLevelExtension("x1/x.2/x.3/myFile.aaa.bbb", 1)
    Debug.Assert result = "bbb"
    result = UtilsIO.getFileNthLevelExtension("myFile.aaa.bbb", 1)
    Debug.Assert result = "bbb"

    result = UtilsIO.getFileNthLevelExtension("x1/x.2/x.3/myFile.bbb", 1)
    Debug.Assert result = "bbb"
    result = UtilsIO.getFileNthLevelExtension("myFile.bbb", 1)
    Debug.Assert result = "bbb"

    result = UtilsIO.getFileNthLevelExtension("x1/x.2/x.3/myFile.bbb", 0)
    Debug.Assert result = ""
    result = UtilsIO.getFileNthLevelExtension("myFile.bbb", 0)
    Debug.Assert result = ""

    result = UtilsIO.getFileNthLevelExtension("x1/x.2/x.3/myFile.bbb", -1)
    Debug.Assert result = ""
    result = UtilsIO.getFileNthLevelExtension("myFile.bbb", -1)
    Debug.Assert result = ""

    result = UtilsIO.getFileNthLevelExtension("x1/x.2/x.3/myFile.aaa.bbb", 2)
    Debug.Assert result = "aaa"
    result = UtilsIO.getFileNthLevelExtension("myFile.aaa.bbb", 2)
    Debug.Assert result = "aaa"

    result = UtilsIO.getFileNthLevelExtension("x1/x.2/x.3/myFile.aaa.bbb", 3)
    Debug.Assert result = ""
    result = UtilsIO.getFileNthLevelExtension("myFile.aaa.bbb", 3)
    Debug.Assert result = ""
End Sub

Public Sub test_getFile1stLevelExtension()
    Dim result As String

    ' ==================================================
    ' 有文件名
    ' ==================================================
    result = UtilsIO.getFile1stLevelExtension("x1/x2/x3/myFile.aaa.bbb.ccc.ddd")
    Debug.Assert result = "ddd"

    result = UtilsIO.getFile1stLevelExtension("x1/x2/x3/myFile.bbb.ccc.ddd")
    Debug.Assert result = "ddd"

    result = UtilsIO.getFile1stLevelExtension("x1/x2/x3/myFile.ccc.ddd")
    Debug.Assert result = "ddd"

    result = UtilsIO.getFile1stLevelExtension("x1/x2/x3/myFile.ddd")
    Debug.Assert result = "ddd"

    result = UtilsIO.getFile1stLevelExtension("x1/x2/x3/myFile")
    Debug.Assert result = ""

    result = UtilsIO.getFile1stLevelExtension("x1/x2/x3/myFile.")
    Debug.Assert result = ""

    result = UtilsIO.getFile1stLevelExtension("x1/x2/x3/myFile..")
    Debug.Assert result = ""

    result = UtilsIO.getFile1stLevelExtension("x1/x2/x3/myFile.ccc.")
    Debug.Assert result = ""

    result = UtilsIO.getFile1stLevelExtension("x1/x2/x3/myFile..ddd")
    Debug.Assert result = "ddd"

    ' ==================================================
    ' 文件名为空字符串
    ' ==================================================
    result = UtilsIO.getFile1stLevelExtension("x1/x2/x3/.aaa.bbb.ccc.ddd")
    Debug.Assert result = "ddd"

    result = UtilsIO.getFile1stLevelExtension("x1/x2/x3/.bbb.ccc.ddd")
    Debug.Assert result = "ddd"

    result = UtilsIO.getFile1stLevelExtension("x1/x2/x3/.ccc.ddd")
    Debug.Assert result = "ddd"

    result = UtilsIO.getFile1stLevelExtension("x1/x2/x3/.ddd")
    Debug.Assert result = "ddd"

    result = UtilsIO.getFile1stLevelExtension("x1/x2/x3/")
    Debug.Assert result = ""

    result = UtilsIO.getFile1stLevelExtension("x1/x2/x3/.")
    Debug.Assert result = ""

    result = UtilsIO.getFile1stLevelExtension("x1/x2/x3/..")
    Debug.Assert result = ""

    result = UtilsIO.getFile1stLevelExtension("x1/x2/x3/.ccc.")
    Debug.Assert result = ""

    result = UtilsIO.getFile1stLevelExtension("x1/x2/x3/..ddd")
    Debug.Assert result = "ddd"

    ' ==================================================
    ' 不存在前缀路径 + 有文件名
    ' ==================================================
    result = UtilsIO.getFile1stLevelExtension("myFile.aaa.bbb.ccc.ddd")
    Debug.Assert result = "ddd"

    result = UtilsIO.getFile1stLevelExtension("myFile.bbb.ccc.ddd")
    Debug.Assert result = "ddd"

    result = UtilsIO.getFile1stLevelExtension("myFile.ccc.ddd")
    Debug.Assert result = "ddd"

    result = UtilsIO.getFile1stLevelExtension("myFile.ddd")
    Debug.Assert result = "ddd"

    result = UtilsIO.getFile1stLevelExtension("myFile")
    Debug.Assert result = ""

    result = UtilsIO.getFile1stLevelExtension("myFile.")
    Debug.Assert result = ""

    result = UtilsIO.getFile1stLevelExtension("myFile..")
    Debug.Assert result = ""

    result = UtilsIO.getFile1stLevelExtension("myFile.ccc.")
    Debug.Assert result = ""

    result = UtilsIO.getFile1stLevelExtension("myFile..ddd")
    Debug.Assert result = "ddd"

    ' ==================================================
    ' 不存在前缀路径 + 文件名为空字符串
    ' ==================================================
    result = UtilsIO.getFile1stLevelExtension(".aaa.bbb.ccc.ddd")
    Debug.Assert result = "ddd"

    result = UtilsIO.getFile1stLevelExtension(".bbb.ccc.ddd")
    Debug.Assert result = "ddd"

    result = UtilsIO.getFile1stLevelExtension(".ccc.ddd")
    Debug.Assert result = "ddd"

    result = UtilsIO.getFile1stLevelExtension(".ddd")
    Debug.Assert result = "ddd"

    result = UtilsIO.getFile1stLevelExtension("")
    Debug.Assert result = ""

    result = UtilsIO.getFile1stLevelExtension(".")
    Debug.Assert result = ""

    result = UtilsIO.getFile1stLevelExtension("..")
    Debug.Assert result = ""

    result = UtilsIO.getFile1stLevelExtension(".ccc.")
    Debug.Assert result = ""

    result = UtilsIO.getFile1stLevelExtension("..ddd")
    Debug.Assert result = "ddd"

    ' ==================================================
    ' 前缀路径中存在 .
    ' ==================================================
    result = UtilsIO.getFile1stLevelExtension("x1/x2/x.3/myFile.aaa")
    Debug.Assert result = "aaa"

    result = UtilsIO.getFile1stLevelExtension("x1/x.2/x.3/myFile")
    Debug.Assert result = ""

    result = UtilsIO.getFile1stLevelExtension("x1/x.2/x.3/myFile.aaa.bbb")
    Debug.Assert result = "bbb"

    ' ==================================================
    ' 级别边界测试 .
    ' ==================================================
    result = UtilsIO.getFile1stLevelExtension("x1/x2/x.3/myFile.aaa")
    Debug.Assert result = "aaa"

    result = UtilsIO.getFile1stLevelExtension("x1/x2/x.3/myFile.aaa.bbb")
    Debug.Assert result = "bbb"

    result = UtilsIO.getFile1stLevelExtension("x1/x2/x.3/myFile.xxx.aaa.bbb")
    Debug.Assert result = "bbb"
End Sub

Public Sub test_getFile2ndLevelExtension()
    Dim result As String

    ' ==================================================
    ' 有文件名
    ' ==================================================
    result = UtilsIO.getFile2ndLevelExtension("x1/x2/x3/myFile.aaa.bbb.ccc.ddd")
    Debug.Assert result = "ccc"

    result = UtilsIO.getFile2ndLevelExtension("x1/x2/x3/myFile.bbb.ccc.ddd")
    Debug.Assert result = "ccc"

    result = UtilsIO.getFile2ndLevelExtension("x1/x2/x3/myFile.ccc.ddd")
    Debug.Assert result = "ccc"

    result = UtilsIO.getFile2ndLevelExtension("x1/x2/x3/myFile.ddd")
    Debug.Assert result = ""

    result = UtilsIO.getFile2ndLevelExtension("x1/x2/x3/myFile")
    Debug.Assert result = ""

    result = UtilsIO.getFile2ndLevelExtension("x1/x2/x3/myFile.")
    Debug.Assert result = ""

    result = UtilsIO.getFile2ndLevelExtension("x1/x2/x3/myFile..")
    Debug.Assert result = ""

    result = UtilsIO.getFile2ndLevelExtension("x1/x2/x3/myFile.ccc.")
    Debug.Assert result = "ccc"

    result = UtilsIO.getFile2ndLevelExtension("x1/x2/x3/myFile..ddd")
    Debug.Assert result = ""

    ' ==================================================
    ' 文件名为空字符串
    ' ==================================================
    result = UtilsIO.getFile2ndLevelExtension("x1/x2/x3/.aaa.bbb.ccc.ddd")
    Debug.Assert result = "ccc"

    result = UtilsIO.getFile2ndLevelExtension("x1/x2/x3/.bbb.ccc.ddd")
    Debug.Assert result = "ccc"

    result = UtilsIO.getFile2ndLevelExtension("x1/x2/x3/.ccc.ddd")
    Debug.Assert result = "ccc"

    result = UtilsIO.getFile2ndLevelExtension("x1/x2/x3/.ddd")
    Debug.Assert result = ""

    result = UtilsIO.getFile2ndLevelExtension("x1/x2/x3/")
    Debug.Assert result = ""

    result = UtilsIO.getFile2ndLevelExtension("x1/x2/x3/.")
    Debug.Assert result = ""

    result = UtilsIO.getFile2ndLevelExtension("x1/x2/x3/..")
    Debug.Assert result = ""

    result = UtilsIO.getFile2ndLevelExtension("x1/x2/x3/.ccc.")
    Debug.Assert result = "ccc"

    result = UtilsIO.getFile2ndLevelExtension("x1/x2/x3/..ddd")
    Debug.Assert result = ""

    ' ==================================================
    ' 不存在前缀路径 + 有文件名
    ' ==================================================
    result = UtilsIO.getFile2ndLevelExtension("myFile.aaa.bbb.ccc.ddd")
    Debug.Assert result = "ccc"

    result = UtilsIO.getFile2ndLevelExtension("myFile.bbb.ccc.ddd")
    Debug.Assert result = "ccc"

    result = UtilsIO.getFile2ndLevelExtension("myFile.ccc.ddd")
    Debug.Assert result = "ccc"

    result = UtilsIO.getFile2ndLevelExtension("myFile.ddd")
    Debug.Assert result = ""

    result = UtilsIO.getFile2ndLevelExtension("myFile")
    Debug.Assert result = ""

    result = UtilsIO.getFile2ndLevelExtension("myFile.")
    Debug.Assert result = ""

    result = UtilsIO.getFile2ndLevelExtension("myFile..")
    Debug.Assert result = ""

    result = UtilsIO.getFile2ndLevelExtension("myFile.ccc.")
    Debug.Assert result = "ccc"

    result = UtilsIO.getFile2ndLevelExtension("myFile..ddd")
    Debug.Assert result = ""

    ' ==================================================
    ' 不存在前缀路径 + 文件名为空字符串
    ' ==================================================
    result = UtilsIO.getFile2ndLevelExtension(".aaa.bbb.ccc.ddd")
    Debug.Assert result = "ccc"

    result = UtilsIO.getFile2ndLevelExtension(".bbb.ccc.ddd")
    Debug.Assert result = "ccc"

    result = UtilsIO.getFile2ndLevelExtension(".ccc.ddd")
    Debug.Assert result = "ccc"

    result = UtilsIO.getFile2ndLevelExtension(".ddd")
    Debug.Assert result = ""

    result = UtilsIO.getFile2ndLevelExtension("")
    Debug.Assert result = ""

    result = UtilsIO.getFile2ndLevelExtension(".")
    Debug.Assert result = ""

    result = UtilsIO.getFile2ndLevelExtension("..")
    Debug.Assert result = ""

    result = UtilsIO.getFile2ndLevelExtension(".ccc.")
    Debug.Assert result = "ccc"

    result = UtilsIO.getFile2ndLevelExtension("..ddd")
    Debug.Assert result = ""

    ' ==================================================
    ' 前缀路径中存在 .
    ' ==================================================
    result = UtilsIO.getFile2ndLevelExtension("x1/x2/x.3/myFile.aaa")
    Debug.Assert result = ""

    result = UtilsIO.getFile2ndLevelExtension("x1/x.2/x.3/myFile")
    Debug.Assert result = ""

    result = UtilsIO.getFile2ndLevelExtension("x1/x.2/x.3/myFile.aaa.bbb")
    Debug.Assert result = "aaa"

    ' ==================================================
    ' 级别边界测试 .
    ' ==================================================
    result = UtilsIO.getFile2ndLevelExtension("x1/x2/x.3/myFile.aaa")
    Debug.Assert result = ""

    result = UtilsIO.getFile2ndLevelExtension("x1/x2/x.3/myFile.aaa.bbb")
    Debug.Assert result = "aaa"

    result = UtilsIO.getFile2ndLevelExtension("x1/x2/x.3/myFile.xxx.aaa.bbb")
    Debug.Assert result = "aaa"
End Sub

Public Sub test_getFile3rdLevelExtension()
    Dim result As String

    ' ==================================================
    ' 有文件名
    ' ==================================================
    result = UtilsIO.getFile3rdLevelExtension("x1/x2/x3/myFile.aaa.bbb.ccc.ddd")
    Debug.Assert result = "bbb"

    result = UtilsIO.getFile3rdLevelExtension("x1/x2/x3/myFile.bbb.ccc.ddd")
    Debug.Assert result = "bbb"

    result = UtilsIO.getFile3rdLevelExtension("x1/x2/x3/myFile.ccc.ddd")
    Debug.Assert result = ""

    result = UtilsIO.getFile3rdLevelExtension("x1/x2/x3/myFile.ddd")
    Debug.Assert result = ""

    result = UtilsIO.getFile3rdLevelExtension("x1/x2/x3/myFile")
    Debug.Assert result = ""

    result = UtilsIO.getFile3rdLevelExtension("x1/x2/x3/myFile.")
    Debug.Assert result = ""

    result = UtilsIO.getFile3rdLevelExtension("x1/x2/x3/myFile..")
    Debug.Assert result = ""

    result = UtilsIO.getFile3rdLevelExtension("x1/x2/x3/myFile.ccc..")
    Debug.Assert result = "ccc"

    result = UtilsIO.getFile3rdLevelExtension("x1/x2/x3/myFile..ddd.")
    Debug.Assert result = ""

    ' ==================================================
    ' 文件名为空字符串
    ' ==================================================
    result = UtilsIO.getFile3rdLevelExtension("x1/x2/x3/.aaa.bbb.ccc.ddd")
    Debug.Assert result = "bbb"

    result = UtilsIO.getFile3rdLevelExtension("x1/x2/x3/.bbb.ccc.ddd")
    Debug.Assert result = "bbb"

    result = UtilsIO.getFile3rdLevelExtension("x1/x2/x3/.ccc.ddd")
    Debug.Assert result = ""

    result = UtilsIO.getFile3rdLevelExtension("x1/x2/x3/.ddd")
    Debug.Assert result = ""

    result = UtilsIO.getFile3rdLevelExtension("x1/x2/x3/")
    Debug.Assert result = ""

    result = UtilsIO.getFile3rdLevelExtension("x1/x2/x3/.")
    Debug.Assert result = ""

    result = UtilsIO.getFile3rdLevelExtension("x1/x2/x3/..")
    Debug.Assert result = ""

    result = UtilsIO.getFile3rdLevelExtension("x1/x2/x3/.ccc..")
    Debug.Assert result = "ccc"

    result = UtilsIO.getFile3rdLevelExtension("x1/x2/x3/..ddd.")
    Debug.Assert result = ""

    ' ==================================================
    ' 不存在前缀路径 + 有文件名
    ' ==================================================
    result = UtilsIO.getFile3rdLevelExtension("myFile.aaa.bbb.ccc.ddd")
    Debug.Assert result = "bbb"

    result = UtilsIO.getFile3rdLevelExtension("myFile.bbb.ccc.ddd")
    Debug.Assert result = "bbb"

    result = UtilsIO.getFile3rdLevelExtension("myFile.ccc.ddd")
    Debug.Assert result = ""

    result = UtilsIO.getFile3rdLevelExtension("myFile.ddd")
    Debug.Assert result = ""

    result = UtilsIO.getFile3rdLevelExtension("myFile")
    Debug.Assert result = ""

    result = UtilsIO.getFile3rdLevelExtension("myFile.")
    Debug.Assert result = ""

    result = UtilsIO.getFile3rdLevelExtension("myFile..")
    Debug.Assert result = ""

    result = UtilsIO.getFile3rdLevelExtension("myFile.ccc..")
    Debug.Assert result = "ccc"

    result = UtilsIO.getFile3rdLevelExtension("myFile..ddd.")
    Debug.Assert result = ""

    ' ==================================================
    ' 不存在前缀路径 + 文件名为空字符串
    ' ==================================================
    result = UtilsIO.getFile3rdLevelExtension(".aaa.bbb.ccc.ddd")
    Debug.Assert result = "bbb"

    result = UtilsIO.getFile3rdLevelExtension(".bbb.ccc.ddd")
    Debug.Assert result = "bbb"

    result = UtilsIO.getFile3rdLevelExtension(".ccc.ddd")
    Debug.Assert result = ""

    result = UtilsIO.getFile3rdLevelExtension(".ddd")
    Debug.Assert result = ""

    result = UtilsIO.getFile3rdLevelExtension("")
    Debug.Assert result = ""

    result = UtilsIO.getFile3rdLevelExtension(".")
    Debug.Assert result = ""

    result = UtilsIO.getFile3rdLevelExtension("..")
    Debug.Assert result = ""

    result = UtilsIO.getFile3rdLevelExtension(".ccc..")
    Debug.Assert result = "ccc"

    result = UtilsIO.getFile3rdLevelExtension("..ddd.")
    Debug.Assert result = ""

    ' ==================================================
    ' 前缀路径中存在 .
    ' ==================================================
    result = UtilsIO.getFile3rdLevelExtension("x1/x2/x.3/myFile.aaa")
    Debug.Assert result = ""

    result = UtilsIO.getFile3rdLevelExtension("x1/x.2/x.3/myFile")
    Debug.Assert result = ""

    result = UtilsIO.getFile3rdLevelExtension("x1/x.2/x.3/myFile.aaa.bbb")
    Debug.Assert result = ""

    result = UtilsIO.getFile3rdLevelExtension("x1/x.2/x.3/myFile.aaa.bbb.ccc")
    Debug.Assert result = "aaa"

    ' ==================================================
    ' 级别边界测试 .
    ' ==================================================
    result = UtilsIO.getFile3rdLevelExtension("x1/x2/x.3/myFile.aaa")
    Debug.Assert result = ""

    result = UtilsIO.getFile3rdLevelExtension("x1/x2/x.3/myFile.aaa.bbb")
    Debug.Assert result = ""

    result = UtilsIO.getFile3rdLevelExtension("x1/x2/x.3/myFile.xxx.aaa.bbb")
    Debug.Assert result = "xxx"
End Sub

Private Sub test_dirExist()
    Dim result As Boolean

    Dim path As String
    path = ThisWorkbook.path & "\testDir"

    ' 1. 执行测试
    result = UtilsIO.dirExist(path)
    Debug.Assert result = False

    ' 2. 创建一个目录
    UtilsIO.mkdirs path

    ' 3. 再次执行测试
    result = UtilsIO.dirExist(path)
    Debug.Assert result = True

    ' 4. 收尾: 删除测试文件
    UtilsIO.rmdir path
End Sub

Private Sub test_filenameListFromFolder()
    ' 1. 创建目录
    Dim dirPath As String
    dirPath = ThisWorkbook.path & "\testDir"
    UtilsIO.mkdirs dirPath

    ' 2. 创建多个文件
    UtilsIO.writeTxtEmptyFileAuto dirPath & "\text.txt"
    UtilsIO.writeTxtEmptyFileAuto dirPath & "\text2.txt"
    UtilsIO.writeTxtEmptyFileAuto dirPath & "\text3.txt"
    UtilsIO.writeTxtEmptyFileAuto dirPath & "\xxxx.txt"

    ' 3. 执行测试
    Dim result As Collection
    Set result = UtilsIO.filenameListFromFolder(dirPath)

    Debug.Assert result.Count = 4
    Debug.Assert result.Item(1) = "text.txt"
    Debug.Assert result.Item(2) = "text2.txt"
    Debug.Assert result.Item(3) = "text3.txt"
    Debug.Assert result.Item(4) = "xxxx.txt"

    ' 4. 执行测试，包含参数 template
    Set result = UtilsIO.filenameListFromFolder(dirPath, "text*.txt")

    Debug.Assert result.Count = 3
    Debug.Assert result.Item(1) = "text.txt"
    Debug.Assert result.Item(2) = "text2.txt"
    Debug.Assert result.Item(3) = "text3.txt"

    ' 5. 收尾: 删除目录
    UtilsIO.rmdir dirPath
End Sub

Private Sub test_filenameListFromFolderByPattern()
    ' 1. 创建目录
    Dim dirPath As String
    dirPath = ThisWorkbook.path & "\testDir"
    UtilsIO.mkdirs dirPath

    ' 2. 创建多个文件
    UtilsIO.writeTxtEmptyFileAuto dirPath & "\text.txt"
    UtilsIO.writeTxtEmptyFileAuto dirPath & "\text2.txt"
    UtilsIO.writeTxtEmptyFileAuto dirPath & "\text3.txt"
    UtilsIO.writeTxtEmptyFileAuto dirPath & "\xxxx.txt"

    ' 3. 执行测试
    Dim result As Collection
    Set result = UtilsIO.filenameListFromFolderByPattern(dirPath, "text.*\.txt")

    ' 4. 检查结果
    Debug.Assert result.Count = 3
    Debug.Assert result.Item(1) = "text.txt"
    Debug.Assert result.Item(2) = "text2.txt"
    Debug.Assert result.Item(3) = "text3.txt"

    ' 4. 收尾: 删除目录
    UtilsIO.rmdir dirPath
End Sub

Private Sub test_getFirstMatchedFilenameFromFolder()
    ' 1. 创建目录
    Dim dirPath As String
    dirPath = ThisWorkbook.path & "\testDir"
    UtilsIO.mkdirs dirPath

    ' 2. 创建多个文件
    UtilsIO.writeTxtEmptyFileAuto dirPath & "\text.txt"
    UtilsIO.writeTxtEmptyFileAuto dirPath & "\text2.txt"
    UtilsIO.writeTxtEmptyFileAuto dirPath & "\text3.txt"
    UtilsIO.writeTxtEmptyFileAuto dirPath & "\xxxx.txt"

    ' 3. 执行测试
    Dim result As String
    result = UtilsIO.getFirstMatchedFilenameFromFolder(dirPath, "text*.txt")

    ' 4. 检查结果
    Debug.Assert result = "text.txt"

    ' 4. 收尾: 删除目录
    UtilsIO.rmdir dirPath
End Sub

Private Sub test_getFirstMatchedFilenameFromFolderByPattern()
    ' 1. 创建目录
    Dim dirPath As String
    dirPath = ThisWorkbook.path & "\testDir"
    UtilsIO.mkdirs dirPath

    ' 2. 创建多个文件
    UtilsIO.writeTxtEmptyFileAuto dirPath & "\text.txt"
    UtilsIO.writeTxtEmptyFileAuto dirPath & "\text2.txt"
    UtilsIO.writeTxtEmptyFileAuto dirPath & "\text3.txt"
    UtilsIO.writeTxtEmptyFileAuto dirPath & "\xxxx.txt"

    ' 3. 执行测试
    Dim result As String
    result = UtilsIO.getFirstMatchedFilenameFromFolderByPattern(dirPath, "text.+\.txt")

    ' 4. 检查结果
    Debug.Assert result = "text2.txt"

    ' 4. 收尾: 删除目录
    UtilsIO.rmdir dirPath
End Sub

Private Sub test_walkFolderAndGetFilePathList()
    ' 1. 创建 2 级目录
    Dim dirPath As String
    Dim dirPath2 As String
    dirPath = ThisWorkbook.path & "\testDir"
    dirPath2 = dirPath & "\testDir2"
    UtilsIO.mkdirs dirPath
    UtilsIO.mkdirs dirPath2

    ' 2. 创建多个文件
    Dim fp1 As String
    Dim fp2 As String
    Dim fp3 As String
    Dim fp4 As String
    Dim fp5 As String
    fp1 = dirPath & "\text.txt"
    fp2 = dirPath & "\text2.txt"
    fp3 = dirPath & "\xxx.txt"
    fp4 = dirPath2 & "\text.txt"
    fp5 = dirPath2 & "\xxx.txt"
    UtilsIO.writeTxtEmptyFileAuto fp1
    UtilsIO.writeTxtEmptyFileAuto fp2
    UtilsIO.writeTxtEmptyFileAuto fp3
    UtilsIO.writeTxtEmptyFileAuto fp4
    UtilsIO.writeTxtEmptyFileAuto fp5

    ' 3. 执行测试，没有参数 template
    Dim result As Collection
    Set result = UtilsIO.walkFolderAndGetFilePathList(dirPath)

    ' 4. 检查结果
    Debug.Assert result.Count = 5
    Debug.Assert result.Item(1) = fp1
    Debug.Assert result.Item(2) = fp2
    Debug.Assert result.Item(3) = fp3
    Debug.Assert result.Item(4) = fp4
    Debug.Assert result.Item(5) = fp5

    ' 5. 执行测试，包含参数 template
    Set result = UtilsIO.walkFolderAndGetFilePathList(dirPath, "text*.txt")

    ' 6. 检查结果
    Debug.Assert result.Count = 3
    Debug.Assert result.Item(1) = fp1
    Debug.Assert result.Item(2) = fp2
    Debug.Assert result.Item(3) = fp4

    ' 5. 收尾: 删除目录
    UtilsIO.rmdir dirPath
End Sub

Private Sub test_walkFolderAndGetFilePathListByPattern()
    ' 1. 创建 2 级目录
    Dim dirPath As String
    Dim dirPath2 As String
    dirPath = ThisWorkbook.path & "\testDir"
    dirPath2 = dirPath & "\testDir2"
    UtilsIO.mkdirs dirPath
    UtilsIO.mkdirs dirPath2

    ' 2. 创建多个文件
    Dim fp1 As String
    Dim fp2 As String
    Dim fp3 As String
    Dim fp4 As String
    Dim fp5 As String
    fp1 = dirPath & "\text.txt"
    fp2 = dirPath & "\text2.txt"
    fp3 = dirPath & "\xxx.txt"
    fp4 = dirPath2 & "\text.txt"
    fp5 = dirPath2 & "\xxx.txt"
    UtilsIO.writeTxtEmptyFileAuto fp1
    UtilsIO.writeTxtEmptyFileAuto fp2
    UtilsIO.writeTxtEmptyFileAuto fp3
    UtilsIO.writeTxtEmptyFileAuto fp4
    UtilsIO.writeTxtEmptyFileAuto fp5

    ' 3. 执行测试，没有参数 template
    Dim result As Collection
    Set result = UtilsIO.walkFolderAndGetFilePathListByPattern(dirPath, "text.*\.txt")

    ' 6. 检查结果
    Debug.Assert result.Count = 3
    Debug.Assert result.Item(1) = fp1
    Debug.Assert result.Item(2) = fp2
    Debug.Assert result.Item(3) = fp4

    ' 5. 收尾: 删除目录
    UtilsIO.rmdir dirPath
End Sub

Private Sub test_filepathListFromFolder()
    ' 1. 创建目录
    Dim dirPath As String
    dirPath = ThisWorkbook.path & "\testDir"
    UtilsIO.mkdirs dirPath

    ' 2. 创建多个文件
    Dim fp1 As String
    Dim fp2 As String
    Dim fp3 As String
    Dim fp4 As String
    fp1 = dirPath & "\text.txt"
    fp2 = dirPath & "\text2.txt"
    fp3 = dirPath & "\text3.txt"
    fp4 = dirPath & "\xxxx.txt"

    UtilsIO.writeTxtEmptyFileAuto fp1
    UtilsIO.writeTxtEmptyFileAuto fp2
    UtilsIO.writeTxtEmptyFileAuto fp3
    UtilsIO.writeTxtEmptyFileAuto fp4

    ' 3. 执行测试
    Dim result As Collection
    Set result = UtilsIO.filepathListFromFolder(dirPath)

    Debug.Assert result.Count = 4
    Debug.Assert result.Item(1) = fp1
    Debug.Assert result.Item(2) = fp2
    Debug.Assert result.Item(3) = fp3
    Debug.Assert result.Item(4) = fp4

    ' 4. 执行测试，包含参数 template
    Set result = UtilsIO.filepathListFromFolder(dirPath, "text*.txt")

    Debug.Assert result.Count = 3
    Debug.Assert result.Item(1) = fp1
    Debug.Assert result.Item(2) = fp2
    Debug.Assert result.Item(3) = fp3

    ' 5. 收尾: 删除目录
    UtilsIO.rmdir dirPath
End Sub

Private Sub test_filepathListFromFolderByPattern()
    ' 1. 创建目录
    Dim dirPath As String
    dirPath = ThisWorkbook.path & "\testDir"
    UtilsIO.mkdirs dirPath

    ' 2. 创建多个文件
    Dim fp1 As String
    Dim fp2 As String
    Dim fp3 As String
    Dim fp4 As String
    fp1 = dirPath & "\text.txt"
    fp2 = dirPath & "\text2.txt"
    fp3 = dirPath & "\text3.txt"
    fp4 = dirPath & "\xxxx.txt"

    UtilsIO.writeTxtEmptyFileAuto fp1
    UtilsIO.writeTxtEmptyFileAuto fp2
    UtilsIO.writeTxtEmptyFileAuto fp3
    UtilsIO.writeTxtEmptyFileAuto fp4

    ' 3. 执行测试
    Dim result As Collection
    Set result = UtilsIO.filepathListFromFolderByPattern(dirPath, "text.*\.txt")

    ' 4. 检查结果
    Debug.Assert result.Count = 3
    Debug.Assert result.Item(1) = fp1
    Debug.Assert result.Item(2) = fp2
    Debug.Assert result.Item(3) = fp3

    ' 5. 收尾: 删除目录
    UtilsIO.rmdir dirPath
End Sub

Private Sub test_getFirstMatchedFilepathFromFolder()
    ' 1. 创建目录
    Dim dirPath As String
    dirPath = ThisWorkbook.path & "\testDir"
    UtilsIO.mkdirs dirPath

    ' 2. 创建多个文件
    Dim fp1 As String
    Dim fp2 As String
    Dim fp3 As String
    Dim fp4 As String
    fp1 = dirPath & "\text.txt"
    fp2 = dirPath & "\text2.txt"
    fp3 = dirPath & "\text3.txt"
    fp4 = dirPath & "\xxxx.txt"

    UtilsIO.writeTxtEmptyFileAuto fp1
    UtilsIO.writeTxtEmptyFileAuto fp2
    UtilsIO.writeTxtEmptyFileAuto fp3
    UtilsIO.writeTxtEmptyFileAuto fp4

    ' 3. 执行测试
    Dim result As String
    result = UtilsIO.getFirstMatchedFilepathFromFolder(dirPath, "text*.txt")

    ' 4. 执行测试，包含参数 template
    Debug.Assert result = fp1

    ' 5. 收尾: 删除目录
    UtilsIO.rmdir dirPath
End Sub

Private Sub test_getFirstMatchedFilepathFromFolderByPattern()
    ' 1. 创建目录
    Dim dirPath As String
    dirPath = ThisWorkbook.path & "\testDir"
    UtilsIO.mkdirs dirPath

    ' 2. 创建多个文件
    Dim fp1 As String
    Dim fp2 As String
    Dim fp3 As String
    Dim fp4 As String
    fp1 = dirPath & "\text.txt"
    fp2 = dirPath & "\text2.txt"
    fp3 = dirPath & "\text3.txt"
    fp4 = dirPath & "\xxxx.txt"

    UtilsIO.writeTxtEmptyFileAuto fp1
    UtilsIO.writeTxtEmptyFileAuto fp2
    UtilsIO.writeTxtEmptyFileAuto fp3
    UtilsIO.writeTxtEmptyFileAuto fp4

    ' 3. 执行测试
    Dim result As String
    result = UtilsIO.getFirstMatchedFilepathFromFolderByPattern(dirPath, "text.+\.txt")

    ' 4. 执行测试，包含参数 template
    Debug.Assert result = fp2

    ' 5. 收尾: 删除目录
    UtilsIO.rmdir dirPath
End Sub

Private Sub test_pathExist()
    Dim path As String
    path = ThisWorkbook.path & "\text.txt"

    ' 1. 执行测试
    Debug.Assert UtilsIO.pathExist(path) = False

    ' 2. 创建文件
    UtilsIO.writeTxtEmptyFileAuto path

    ' 3. 执行测试
    Debug.Assert UtilsIO.pathExist(path) = True

    ' 4. 收尾: 删除文件
    UtilsIO.tryDeleteFile path
End Sub

Private Sub test_isFile()
    ' 1. 创建文件
    Dim path As String
    path = ThisWorkbook.path & "\text.txt"
    UtilsIO.writeTxtEmptyFileAuto path

    ' 2. 执行测试
    Debug.Assert UtilsIO.isFile(path) = True

    ' 3. 收尾: 删除文件
    UtilsIO.tryDeleteFile path

    ' 4. 创建目录
    Dim dirPath As String
    dirPath = ThisWorkbook.path & "\testDir"
    UtilsIO.mkdirs dirPath

    ' 5. 执行测试
    Debug.Assert UtilsIO.isFile(dirPath) = False

    ' 6. 收尾: 删除目录
    UtilsIO.rmdir dirPath
End Sub

Private Sub test_isDir()
    ' 1. 创建文件
    Dim path As String
    path = ThisWorkbook.path & "\text.txt"
    UtilsIO.writeTxtEmptyFileAuto path

    ' 2. 执行测试
    Debug.Assert UtilsIO.isDir(path) = False

    ' 3. 收尾: 删除文件
    UtilsIO.tryDeleteFile path

    ' 4. 创建目录
    Dim dirPath As String
    dirPath = ThisWorkbook.path & "\testDir"
    UtilsIO.mkdirs dirPath

    ' 5. 执行测试
    Debug.Assert UtilsIO.isDir(dirPath) = True

    ' 6. 收尾: 删除目录
    UtilsIO.rmdir dirPath
End Sub

Private Sub test_joinPath()
    Dim result As String

    ' ---------case1---------
    result = joinPath()
    Debug.Assert result = ""

    ' ---------case2---------
    result = joinPath("111")
      Debug.Assert result = "111"

    ' ---------case3---------
    result = joinPath("111", "222", "333")
    Debug.Assert result = "111\222\333"

    ' ---------case4---------
    result = joinPath("111\")
    Debug.Assert result = "111"

    ' ---------case5---------
    result = joinPath("111\\")
    Debug.Assert result = "111"

    ' ---------case6---------
    result = joinPath("111\\\\\")
    Debug.Assert result = "111"

    ' ---------case7---------
    result = joinPath("111\", "222\", "333\")
    Debug.Assert result = "111\222\333"

    ' ---------case8---------
    result = joinPath("111\\\", "222\\\", "333\\\")
    Debug.Assert result = "111\222\333"
End Sub

Private Sub test_dirname()
    Dim path As String
    Dim result As String

    ' -----------case1-------------
    path = "C:\test\test.txt"
    result = UtilsIO.dirname(path)
    Debug.Assert result = "C:\test"

    ' -----------case2-------------
    path = "C:\test\test2"
    result = UtilsIO.dirname(path)
    Debug.Assert result = "C:\test"

    ' -----------case3-------------
    path = "C:\test"
    result = UtilsIO.dirname(path)
    Debug.Assert result = "C:"

    ' -----------case4-------------
    path = "C:\"
    result = UtilsIO.dirname(path)
    Debug.Assert result = "C:"

    ' -----------case5-------------
    path = "C:"
    result = UtilsIO.dirname(path)
    Debug.Assert result = "C:"

    ' -----------case6-------------
    path = "C:\test\test2\"
    result = UtilsIO.dirname(path)
    Debug.Assert result = "C:\test"
End Sub

Private Sub test_getBasename()
    Dim path As String
    Dim result As String

    '-----------case1-------------
    path = "C:\test\test.txt"
    result = UtilsIO.getBasename(path)
    Debug.Assert result = "test.txt"

    '-----------case2-------------
    path = "test.txt"
    result = UtilsIO.getBasename(path)
    Debug.Assert result = "test.txt"

    '-----------case3-------------
    path = "C:\test\test2"
    result = UtilsIO.getBasename(path)
    Debug.Assert result = "test2"
End Sub

Private Sub test_getThisWorkbookDir()
    Dim currentDir As String
    currentDir = UtilsIO.getThisWorkbookDir
    Debug.Assert currentDir = ThisWorkbook.path
End Sub

Private Sub test_isWinAbsolutePath()
    Debug.Assert UtilsIO.isWinAbsolutePath("C:\xxxx") = True
    Debug.Assert UtilsIO.isWinAbsolutePath("C:\") = True
    Debug.Assert UtilsIO.isWinAbsolutePath("A:\") = True
    Debug.Assert UtilsIO.isWinAbsolutePath("Z:\") = True
    Debug.Assert UtilsIO.isWinAbsolutePath("AA:\") = False
    Debug.Assert UtilsIO.isWinAbsolutePath("C:") = False
    Debug.Assert UtilsIO.isWinAbsolutePath("C\") = False
    Debug.Assert UtilsIO.isWinAbsolutePath(":\xxxx") = False
    Debug.Assert UtilsIO.isWinAbsolutePath("C:/xxxx") = False
    Debug.Assert UtilsIO.isWinAbsolutePath("/xxxx") = False
    Debug.Assert UtilsIO.isWinAbsolutePath("/") = False
End Sub
